package com.example.mapper;

import com.example.entity.MI_Table;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author liu
 * @since 2022-03-19
 */

@Mapper
@Repository
public interface MedicineInfoMapper {

    @Insert("INSERT INTO `t_medicine_info` \n" +
            "(m_name,m_inventory,m_unit,m_specification,m_price,m_amount,m_purchasenum,m_manufacturer,m_majorfunction,m_adversereaction,m_taboos\n" +
            ",m_validuntil,m_kinds,m_batchnum,m_approvalnum,m_otc,m_userid)\n" +
            "VALUES (#{m_name},#{m_inventory},#{m_unit},#{m_specification}," +
            "#{m_price},#{m_amount},#{m_purchasenum},#{m_manufacturer},#{m_majorfunction},#{m_adversereaction},#{m_taboos}," +
            "#{m_validuntil},#{m_kinds},#{m_batchnum},#{m_approvalnum},#{m_otc},#{m_userid})")
    void insert_MedicineInfo(@Param ("m_name")String m_name,@Param ("m_inventory")int m_inventory,@Param ("m_unit")String m_unit,
                             @Param ("m_specification")String m_specification,@Param ("m_price")double m_price,
                             @Param ("m_amount")double m_amount,@Param ("m_purchasenum")int m_purchasenum,@Param ("m_manufacturer")String m_manufacturer,
                             @Param ("m_majorfunction")String m_majorfunction,@Param ("m_adversereaction")String m_adversereaction,
                             @Param ("m_taboos")String m_taboos,@Param ("m_validuntil")String m_validuntil,
                             @Param ("m_kinds")String m_kinds,@Param ("m_batchnum")String m_batchnum,
                             @Param ("m_approvalnum")String m_approvalnum,@Param ("m_otc")String m_otc,@Param("m_userid") Integer m_userid);

    @Select("SELECT m_id,m_batchnum,m_validuntil,m_amount,m_purchasenum FROM `t_medicine_info` WHERE m_name = #{m_name}")
    List<MI_Table> queryBacthNumByName(@Param ("m_name")String m_name);

    @Update("UPDATE `t_medicine_info` set m_inventory = #{m_inventory},m_amount=#{m_amount},m_purchasenum=#{m_purchasenum} where m_id = #{m_id}")
    void updateMedInfoById(@Param("m_id") int m_id,@Param("m_inventory") int m_inventory,
                            @Param("m_amount") double m_amount,@Param("m_purchasenum") double m_purchasenum);

    @Delete("DELETE FROM t_medicine_info WHERE m_id=#{m_id} and m_userid=#{m_userid}")
    void deleteMedInfoById(@Param("m_id") int m_id,@Param("m_userid") int userid);
}
